clear all

set mem 250m
set more off
set matsiz 8000
/*choose directory*/
cd "C:\Users\bond10\Desktop\RA\Test Scores\Paper\replication files" 
use ECLSbondlang.dta, clear

/*Normalize test scores to be between 0 and 1 to match transformation*/
replace readfallk=readfallk/180
replace readspringk = readspringk/180
replace readspring1 = readspring1/180
replace readspring3 = readspring3/180


/*Fall-K R2 Transformation*/
scalar B1 = 2959.23268775735
scalar B2 = 12710.2673064966
scalar B3 = 29460.2745370992
scalar B4 = 36857.0819681668
scalar B5 = 23279.9123969347
scalar B6 = 5752.4599459532
scalar k = -1.158344
scalar N1 = -428.334127060023

foreach x in fallk springk spring1 spring3         {
gen r2transform`x' = B1*(read`x' + k) + B2*(read`x' + k)^2 + B3*(read`x' + k)^3 + B4*(read`x' + k)^4 + B5*(read`x' + k)^5 + B6*(read`x' + k)^6 - N1
                                                       }
foreach x in fallk springk spring1 spring3  {
qui: summ r2transform`x' [aweight=weights]
scalar mn = r(mean)
scalar stnd = r(sd)
qui: gen r2transform`x'std = (r2transform`x'-mn)/stnd
qui:reg r2transform`x'std black hispanic asian other [pweight=weights], robust
est sto A`x'
}

est tab Afallk Aspringk Aspring1 Aspring3, b se keep(black)
